package org.jeecg.modules.ptUsers.service.impl;

import org.jeecg.common.api.vo.Result;
import org.jeecg.common.constant.CommonConstant;
import org.jeecg.modules.base.service.BaseCommonService;
import org.jeecg.modules.base.service.impl.BaseCommonServiceImpl;
import org.jeecg.modules.ptUsers.entity.PtUsers;
import org.jeecg.modules.ptUsers.mapper.PtUsersMapper;
import org.jeecg.modules.ptUsers.service.IPtUsersService;
import org.jeecg.modules.system.entity.SysUser;
import org.jeecg.modules.system.mapper.SysUserMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;

import javax.annotation.Resource;

/**
 * @Description: 会员信息
 * @Author: jeecg-boot
 * @Date:   2023-02-22
 * @Version: V1.0
 */
@Service
public class PtUsersServiceImpl extends ServiceImpl<PtUsersMapper, PtUsers> implements IPtUsersService {

    @Resource
    private BaseCommonService baseCommonService;

    @Autowired
    private PtUsersMapper usersMapper;


    @Override
    public PtUsers getUserByName(String username) {
        return usersMapper.getUserByName(username);
    }

    @Override
    public PtUsers getUserByPhone(String phone) {
        return usersMapper.getUserByPhone(phone);
    }

    @Override
    public Result checkUserIsEffective(PtUsers user) {
        Result<?> result = new Result<Object>();
        //情况1：根据用户信息查询，该用户不存在
        if (user == null) {
            result.error500("该用户不存在，请注册");
            baseCommonService.addLog("用户登录失败，用户不存在！", CommonConstant.LOG_TYPE_1, null);
            return result;
        }
        //情况2：根据用户信息查询，该用户已注销
        //update-begin---author:王帅   Date:20200601  for：if条件永远为falsebug------------
//        if (CommonConstant.DEL_FLAG_1.equals(user.getDelFlag())) {
//            //update-end---author:王帅   Date:20200601  for：if条件永远为falsebug------------
//            baseCommonService.addLog("用户登录失败，用户名:" + user.getUserName() + "已注销！", CommonConstant.LOG_TYPE_1, null);
//            result.error500("该用户已注销");
//            return result;
//        }
        //情况3：根据用户信息查询，该用户已冻结
        if (CommonConstant.USER_FREEZE.equals(user.getUserState())) {
            baseCommonService.addLog("用户登录失败，用户名:" + user.getUserName() + "已冻结！", CommonConstant.LOG_TYPE_1, null);
            result.error500("该用户已冻结");
            return result;
        }
        return result;
    }
}
